
package com.kweative.model.query;

import com.kweative.model.Table;
import com.kweative.model.exception.ColumnNotFoundException;
import com.kweative.model.relation.Relation;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author henrik
 */
public class Delete<T extends Table> extends WhereStatement<Delete<T>,T> implements NonQueryStatement {

    public Delete(T primTable) {
        super(primTable);
    }
    public Delete relationTo(Relation relation,Object ... values) {
        return this;
    }
    
    public void first() {
       
    }
    public void all(int offset,int limit) {
    
    }
    public void all(int limit) {
    
    }
    public void all() {
    
    }
    @Override
    public String compile() {
        StringBuilder sb = new StringBuilder();
        try {
            String wherePhrase = this.compileWherePhrase();
            String orderPhrase = this.compileOrderPhrase();
            String limitPhrase = this.compileLimitPhrase();

            sb.append(String.format("DELETE FROM %s",QueryUtil.formatTable(getTable())));

            if (!wherePhrase.isEmpty())
                sb.append(" WHERE ").append(wherePhrase);
            sb.append(orderPhrase);
            sb.append(limitPhrase);
        } catch (ColumnNotFoundException ex) {
            Logger.getLogger(Delete.class.getName()).log(Level.SEVERE, null, ex);
        }
        return sb.toString();
    }
    
}
